package com.itcam.ds_.redblacktree;


import static com.itcam.ds_.redblacktree.RedBlackTree.Color.BLACK;
import static com.itcam.ds_.redblacktree.RedBlackTree.Color.RED;

/**
 * Author:Cammy.Wu
 * Date:2024-06-06
 * Description:
 */

public class RedBlackTree {
    enum Color {
        RED,
        BLACK
    }


    private static class Node {
        int key;
        Object value;
        Node lc;
        Node rc;
        Node parent;
        Color color = RED;


        // 是否是左孩子
        boolean isLeftChild() {
            return parent != null && parent.lc == this;
        }

        // 叔叔
        Node uncle() {
            if (parent == null || parent.parent == null) {
                return null;
            }
            if (parent.isLeftChild()) {
                return parent.parent.rc;
            } else {
                return parent.parent.lc;
            }
        }

        // 兄弟
        Node Sibling() {
            if (parent == null) {
                return null;
            }
            if (this.isLeftChild()) {
                return parent.rc;
            } else {
                return parent.lc;
            }
        }

    }

    private Node root;


    // 判断红
    boolean isRed(Node node) {
        return node != null && node.color == RED;
    }

    // 判断黑
    boolean isBlack(Node node) {
        return node == null || node.color == BLACK;
    }

}
